#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
using namespace std;
const int N = 1e5 + 10;
typedef long long ll;
int a[N];
ll sum;
int main()
{
	int n, x;
	cin >> n >> x;
	for (int i = 1; i <= n; i++)
		cin >> a[i];
	if (a[1] > x)
		sum = a[1] - x;
	
	for (int i = 2; i <= n; i++)
	{
		if (a[i] + a[i - 1] > x)
		{
			sum += a[i] + a[i - 1] - x;
			a[i] = x - a[i - 1];
		}
	}
	cout << sum << endl;
	return 0;
}